package com.flca.dbs.berkeley;

import java.util.Map;

import com.flca.frw.dao.DaoFactory;
import com.flca.frw.dao.PersistenceType;
import com.flca.frw.dao.RegisterDatabase;

/**
 * this is a helper class to create a RegisterDatabase object voor Jpa based persistence
 * @author nly36776
 *
 */
public class BerkeleyDatabase implements RegisterDatabase {

	private String username;
	private String password;
	private String unitName;
	private String url;
	private Class<?> driverClass;
	private Class<?> dialect;
	private String testQuery;
	private Map<String, String> options;
	private PersistenceType type;
	private DaoFactory daoFactory;
	
	/**
	 * Use this method to register a database when you supply all settings persistence.xml
	 * @param dbsname
	 * @param defaultDatabase
	 */
	public BerkeleyDatabase(String dbsname) {
		super();
		this.unitName = dbsname;
		this.type = PersistenceType.BERKELEY;
		this.daoFactory = new BerkeleyDaoFactory();
	}

	/**
	 * With this method you can register a database while passing parameters along.
	 * You still need the persistence.xml to define the classes.
	 * note the persistence.xml unit name must corresponde with unitname argument 
	 * @param unitName this is the name that corresponds with the name in persistence.xml and used when to obtain a connection from the commpool, unless 
	 * this will be the default database
	 * @param url 
	 * @param driverClass
	 * @param dialect
	 * @param username
	 * @param password
	 * @param aDefaultDbs
	 */
	public BerkeleyDatabase(
			String unitName, 
			String url, 
			Class<?> driverClass, 
			Class<?> dialect,
			String username, 
			String password) 
	{
		this(unitName);
		this.url = url;
		this.driverClass = driverClass;
		this.dialect = dialect;
		this.username = username;
		this.password = password;
		this.daoFactory = new BerkeleyDaoFactory();
	}

	@Override
	public PersistenceType getPersistenceType() {
		return type;
	}

	@Override
	public String getUnitName() {
		return unitName;
	}

	@Override
	public String getUsername() {
		return username;
	}

	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public Class<?> getDriver() {
		return driverClass;
	}

	@Override
	public String getUrl() {
		return url;
	}

	@Override
	public Map<String, String> getOptions() {
		return options;
	}

	@Override
	public String getTestQuery() {
		return testQuery;
	}

	@Override
	public DaoFactory getDaoFactory() {
		return daoFactory;
	}

	
	//--- getters & setters
	
	public void setTestQuery(String testQuery) {
		this.testQuery = testQuery;
	}

	public void setOptions(Map<String, String> options) {
		this.options = options;
	}

	public Class<?> getDialect() {
		return dialect;
	}

	
	public Class<?> getDriverClass() {
		return driverClass;
	}

	public void setDriverClass(Class<?> driverClass) {
		this.driverClass = driverClass;
	}

	public PersistenceType getType() {
		return type;
	}

	public void setType(PersistenceType type) {
		this.type = type;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUnitName(String dbsname) {
		this.unitName = dbsname;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setDialect(Class<?> dialect) {
		this.dialect = dialect;
	}

	public void setDaoFactory(DaoFactory daoFactory) {
		this.daoFactory = daoFactory;
	}

}
